import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

import { AreaMapRightData, ColumnChart, CurveChart, DashboardTop, OrganizationInfo, PieChart } from '@app/core/domain/dashboard';
import { RequestParams } from '@app/core/domain/request-params';

import { BaseHttpService } from '../base-http.service';

@Injectable({
  providedIn: 'root'
})
export class DashboardService {
  constructor(private readonly http: BaseHttpService) {}

  /*
   * get the top number data of dashboard
   *
   * @param {number} dataType
   * @returns {Observable<DashboardTop>}
   *
   * @memberOf DashboardService
   * */
  public getDashboardNumberByType(dataType: number): Observable<DashboardTop> {
    return this.http.get<DashboardTop>(`/api/dashboard/GetDashboardNumberByType?dataType=${dataType}`);
  }

  /**
   * get the pie chart data of dashboard
   *
   * @param {number} dataType
   * @returns {Observable<PieChart>}
   *
   * @memberOf DashboardService
   */
  public getPieChartDataByType(dataType: number): Observable<PieChart[]> {
    return this.http.get<PieChart[]>(`/api/dashboard/GetPieChartDataByType?dataType=${dataType}`);
  }

  /**
   * get the left bottom data
   * @param params
   * @returns
   */
  public getOrganizationList(params: RequestParams | OrganizationInfo): Observable<OrganizationInfo[]> {
    return this.http.get<OrganizationInfo[]>(`/api/IMOrganizationInfo/GetAll`, { ...params });
  }

  /**
   * get the income data of column chart
   * @param dataType
   * @returns
   */
  public getIncomeChartData(dataType: number): Observable<ColumnChart[]> {
    return this.http.get<ColumnChart[]>(`/api/dashboard/GetIncomeByType?dataType=${dataType}`);
  }

  /**
   * get the organization patient info
   * @param dataType
   * @returns
   */
  public getOrganizationPatientInfos(dataType: number, params: RequestParams | OrganizationInfo = {}): Observable<OrganizationInfo[]> {
    return this.http.get<OrganizationInfo[]>(`/api/IMOrganizationInfo/GetOrganizationPatientInfosByType?dataType=${dataType}`, { ...params });
  }

  /**
   * get the curve date below the map
   * @returns
   */
  public getCurveChartData(): Observable<CurveChart> {
    return this.http.get<CurveChart>(`/api/dashboard/GetCurveChartData`);
  }

  /**
   * get the right data of area map
   * @param dataType
   * @returns
   */
  public getAreaMapRightData(dataType: number): Observable<AreaMapRightData> {
    return this.http.get<AreaMapRightData>(`/api/dashboard/GetAreaMapRightData?dataType=${dataType}`);
  }
}
